<%--
   help
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@ tag language="java" pageEncoding="UTF-8"
	deferredSyntaxAllowedAsLiteral="false" trimDirectiveWhitespaces="true"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ attribute name="id" required="true" type="java.lang.String"
	description="唯一标识."%>
<%@ attribute name="name" required="true" type="java.lang.String"
	description="控件的名称."%>
<%@ attribute name="value" required="true" type="java.lang.String"
	description="控件的值."%>

<%@ attribute name="controlType" required="true" type="java.lang.String"
	description="控件类型.包含select等"%>

<%@ attribute name="datasourceEntityId" required="false"
	type="java.lang.String" description="数据源实体."%>

<%@ attribute name="valueField" required="false" type="java.lang.String"
	description="值字段."%>
<%@ attribute name="displayField" required="false"
	type="java.lang.String" description="显示字段."%>
<%@ attribute name="filter" required="false" type="java.lang.String"
	description="过滤."%>

<c:choose>
	<c:when test="${controlType eq 'select'}">
		<select id="${id }" name="${name }"></select>
		<script type="text/javascript">
			$(function() {
				var url = "db/dynamicControl/getDatasource";
				$.getJSON(url, {
					datasourceEntityId : "${datasourceEntityId}",
					valueField :"${valueField}",
					displayField : "${displayField}",
					filter : "${filter}"
				}, function(result) {
					var options = "";
					$(result).each(
						function(index, item) {
							options += "<option value='"+item["${valueField}"]+"'>"
								+ item["${displayField}"] + "</option>";
						});
					$("#${id }").html(options);
				
					$("#${id }").val("${value}");
					$("#${id }").trigger("chosen:updated");
				});

			});
		</script>
	</c:when>

</c:choose>






